package com.huiying.mapper;

import com.huiying.annotation.AutoFile;
import com.huiying.entity.entity.Bid;
import com.huiying.utils.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: lsh
 * @Date: 2024/12/01/11:48
 * @Description: 接单表数据访问类
 */
@Mapper
public interface BidMapper {

    /**
     * 插入接单请求
     * @param bid
     * @return: void
     */
    @AutoFile(OperationType.INSERT)
    @Insert("insert into bid(demand_id, user_id, message, create_time, update_time) " +
            "values (#{demandId},#{userId},#{message},#{createTime},#{updateTime})")
    void insert(Bid bid);

    @Select("select id, demand_id, user_id, message, create_time, update_time from bid " +
            "where user_id = #{userId} and demand_id = #{demandId}")
    Bid getByUserIdWithDemandId(Bid bid);

    @Select("select user_id from bid " +
            "where demand_id = #{demandId}")
    List<Long> getByDemandId(Long demandId);

    @Delete("delete from bid where demand_id = #{demandId}")
    void deleteByDemandId(Long demandId);
}
